home *** CD-ROM | disk | FTP | other *** search
/ FM Towns: Free Software Collection 4 / FM Towns Free Software Collection 4 - Disc 1.iso / t_os / se / se.c next >
Text File  |  1991-10-18  |  8KB  |  355 lines

  1. /*
  2.     音声モードPCMファイル 簡易切り出しツール
  3.         (for FM-Towns GCC Compiler 1.36 with tbios library)
  4.  
  5.     Programed 1991 S.Kamio
  6.     FM-Towns + 2 Mbyte memory + towns-menu + tbios system.
  7.  
  8.     1st version 0.1        july/7/1991
  9. */
  10.  
  11.  
  12. #include <stdio.h>
  13. #include <tbios.h>    /* my header */
  14.  
  15. byte s[256*1024];
  16. byte ss[256*1024];
  17. char fn[16];
  18. int t[256];
  19. int fsize,ffs;
  20.  
  21. void main (uint argc,char *argv[])
  22. {
  23.     uint i,ff;
  24.     int gl=0,gr=639,cl=0;
  25.     byte me[1024];
  26.     FILE *fp,*fopen();
  27.  
  28.     putchar (12);
  29.     for (i=0;i<2048;i++)
  30.         putchar (32);
  31.     putchar (12);
  32.     fsize=_get_file_size(argv[1]);
  33.     if (fsize<0)
  34.     {
  35.         printf ("not find.\n");
  36.         printf ("usage : run386 se.exp <loadname.snd> <outputname.snd>\n");
  37.         printf ("<outputname>は、現在開発中ですので、サポートしていません。\n");
  38.         printf ("<outputname>は、セーブ時に常に指定します。\n");
  39.         printf ("全てのネームに、「.snd」は省略できません。\n");
  40.         exit (1);
  41.     }
  42.     if (fsize>(256*1024))
  43.     {
  44.         printf ("size over.\n");
  45.         exit (1);
  46.     }
  47.     if (argc!=2)
  48.     {
  49.         printf ("no enough parametors.\n");
  50.         exit (1);
  51.     }
  52.     fp=fopen(argv[1],"rb");
  53.     fread (&s[0],1,fsize,fp);
  54.     fclose (fp);
  55.     fsize=fsize-32;
  56.     KBD_init ();
  57.     for (i=128;i<256;i++)
  58.         t[i]=i;
  59.     for (i=0;i<128;i++)
  60.         t[i]=128-i;
  61.     t[255]=254;
  62.  
  63.     VGA480_init ();
  64.     for (i=0;i<64;i++)
  65.         EGB_palette (0,0x20+i,64,0,i);
  66.     disp ();
  67.     KBD_click (1);
  68.     i=KBD_read ();
  69.     while (i!=27)
  70.     {
  71.         if (gl<0)
  72.             gl=0;
  73.         if (gr<0)
  74.             gr=0;
  75.         if (gr>639)
  76.             gr=639;
  77.         if (gl>=gr)
  78.             gl=gr;
  79.         EGB_get (gl,0,gl,255,&me[0]);
  80.         EGB_get (gr,0,gr,255,&me[256]);
  81.         EGB_writecolor (253);
  82.         EGB_line (gl,0,gl,255);
  83.         EGB_line (gr,0,gr,255);
  84.         EGB_writecolor (255);
  85.         EGB_gprint (32,380,"コマンドを入力してください。");
  86.         EGB_gprint (32,400,"キーボードでのみ操作可能です。");
  87.         EGC_linebf256 (0,257,1023,269,2);
  88.         EGC_linebf256 (gl,257,gr,269,221);
  89.         EGB_put (gl,0,gl,255,&me[0]);
  90.         EGB_put (gr,0,gr,255,&me[256]);
  91.         i=KBD_inkey ();
  92.         switch (i)
  93.         {
  94.             case 'p':
  95.             case 'P':
  96.                 play (gl,gr);
  97.                 break;
  98.             case 's':
  99.             case 'S':
  100.                 play (gl,gr);
  101.                 EGC_linebf256 (0,380,1023,399,0);
  102.                 filename_in ();
  103.                 EGC_linebf256 (0,380,1023,511,0);
  104.                 EGB_gprint (32,380,"保存中です。けっこうかかりますよ!");
  105.                 EGB_gprint (32,400,"気長に待っててね!(^_^)");
  106.                 if ((fp=fopen (&fn[0],"wb"))!=NULL)
  107.                 {
  108.                     fwrite (&ss[0],1,ffs,fp);
  109.                     close (fp);
  110.                 }
  111.                 EGC_linebf256 (0,380,1023,511,0);
  112.                 break;
  113.             case 'g':
  114.             case 'G':
  115.                 disp ();
  116.                 break;
  117.             case 29 :
  118.                 if (cl==0)
  119.                     gl--;
  120.                 if (cl!=0)
  121.                     gr--;
  122.                 break;
  123.             case 28 :
  124.                 if (cl==0)
  125.                     gl++;
  126.                 if (cl!=0)
  127.                     gr++;
  128.                 break;
  129.             case '4':
  130.                 if (cl==0)
  131.                     gl-=16;
  132.                 if (cl!=0)
  133.                     gr-=16;
  134.                 break;
  135.             case '6':
  136.                 if (cl==0)
  137.                     gl+=16;
  138.                 if (cl!=0)
  139.                     gr+=16;
  140.                 break;
  141.             case ' ':
  142.                 cl=(cl+1) % 2;
  143.                 EGC_linebf256 (0,360,1023,399,0);
  144.                 if (cl==0)
  145.                 {
  146.                     EGB_gprint (520,380,"pen left.");
  147.                 } else
  148.                 {
  149.                     EGB_gprint (520,380,"pen right.");
  150.                 }
  151.             default :
  152.                 EGC_linebf256 (320,460,1023,511,0);
  153.                 ff=((uint)s[24]+(uint)s[25]*256)*0x62;
  154.                 sprintf ((char *)&me[0],"(%d,%d)  debug %u Hz",gl,gr,ff);
  155.                 EGB_gprint (320,460,&me[0]);
  156.                 break;
  157.         }
  158.     }
  159.     EGB_cls ();
  160.     KBD_click (1);
  161.     EGB_writepage (1);
  162.     EGB_displaypage (1,3);
  163.     printf ("EASY SOUND CUTTER. for all fm-townes with 2 Mbytes memory.\n");
  164.     printf ("   ORICONS console emulators.\n");
  165.     printf ("RUN386 se.exp <filename>\n");
  166.     printf ("   <filename> must be '????.snd'\n");
  167.     printf ("                       June 1991\n");
  168.     byebee_menu ();
  169.     exit (1);
  170. }
  171.  
  172. disp ()
  173. {
  174.     int i;
  175.  
  176.     EGB_backcolor (0x00);
  177.     EGB_cls ();
  178.     EGB_writecolor (0xff);
  179.     for (i=0;i<256;i++)
  180.         EGC_linebf256 (0,i,639,i,0x20+abs((i % 64)-32));
  181.     EGB_line (0,0,639,0);
  182.     EGB_line (0,256,639,256);
  183.     for (i=0;i<fsize;i++)
  184.         EGC_pset256 (i*639/fsize,t[s[i+32]],0x4f+0x80);
  185.     EGB_writecolor (0x68);
  186.     EGB_gprint (5,270,"サウンド切断プログラム(開発途中版) by s.kamio");
  187.     EGB_writecolor (0x72);
  188.     EGB_gprint (20,300,"ESC : END   /  P : PLAY   /  G : FLASH   /  S : SAVE");
  189.     EGB_gprint (20,316,"(<- or 4) Pen move left. / (-> or 6) Pen move right.");
  190.     EGB_gprint (20,332,"SPACE : Pen change.");
  191.     EGB_writecolor (0xff);
  192. }
  193.  
  194. /*
  195.  私の製作したライブラリが、何故か16KHz未満の音声を再生しようとすると
  196.  暴走してしまいます。そのために、一度20KHzまで音声を引き延ばして再生しま
  197.  す。
  198. */
  199.  
  200. ssplay (int fsp)
  201. {
  202.     byte c[340*1024];
  203.     int i,ns,es,dd,ff;
  204.  
  205.     ff=(int)ss[24]+(int)ss[25]*256;
  206.     EGC_linebf256 (0,380,1023,511,0);
  207.     EGB_gprint (32,380,"再生用にデーターの加工をしています。");
  208.     ns=fsp*1960/ff;
  209.     if (ns>(340*1024))
  210.     {
  211.         printf ("memory over.\n");
  212.         EGB_cls ();
  213.         EGB_gprint (0,300,"Out of memory. Fatal error occured!");
  214.         EGB_gprint (0,316,"20KHz play buffer = 340KByte (17 second)");
  215.         exit (1);
  216.     }
  217.     dd=ff/2;
  218.     es=32;
  219.     for (i=32;i<ns;i++)        /* zooming */
  220.     {
  221.         c[i]=(byte)t[((t[ss[es]]*(1960-dd)+t[ss[es+1]]*dd)/1960)];
  222.         dd=dd+ff;
  223.         es=es+(dd/1960);
  224.         dd=dd % 1960;
  225.     }
  226.     for (i=0;i<32;i++)
  227.         c[i]=ss[i];
  228.     EGC_linebf256 (0,380,1023,399,0);
  229.     EGB_gprint (32,380,"確認再生をしています。");
  230.     c[24]=1960 % 256;        /* new pcm frequency = 20 KHz */
  231.     c[25]=1960 / 256;
  232.     c[12]=ns % 256;            /* new size */
  233.     c[13]=(ns/256) % 256;
  234.     c[14]=(ns/256/256) % 256;
  235.     c[15]=ns/256/256/256;
  236.     c[26]=0;                /* not over 20000 Hz */
  237.     c[27]=0;
  238.     c[20]=0;                /* no loop */
  239.     c[21]=0;
  240.     c[22]=0;
  241.     c[23]=0;
  242.     SND_init ();
  243.     SND_mute (0xff);
  244.     SND_evolume (0,127,127);
  245.     SND_voicechannel (3);
  246.     SND_voiceplay (&c[0],71,60,60);
  247.     waite (50);
  248.     while (((SND_pad (1) & 0x10)!=0) && (SND_voicecondition (71)!=0))
  249.         dclock ();
  250.     SND_mute (0x00);
  251.     SND_pcmstop ();
  252.     SND_bye ();
  253.     EGC_linebf256 (0,380,1023,399,0);
  254. }
  255.  
  256. int KBD_inkey ()        /* 入力待ち付のキー入力 */
  257. {
  258.     int i;
  259.  
  260.     while ((i=KBD_read ())==0)
  261.     {
  262.         break_check ();
  263.         dclock ();
  264.     }
  265.     return (i);
  266. }
  267.  
  268. dclock ()
  269. {
  270.     byte c[8192];
  271.     long t;
  272.  
  273.     t=time(0);
  274.     EGC_linebf256 (0,480,1023,496,0);
  275.     waite (8);
  276.     EGB_writecolor (239);
  277.     EGB_gprint (400,480,(char *)ctime((long *)&t));
  278.     EGB_get (400,480,400+8*24,480+15,&c[0]);
  279.     EGB_put (432,270,432+8*24,270+15,&c[0]);
  280.     EGB_writecolor (255);
  281. }
  282.  
  283. play (int gl,int gr)
  284. {
  285.     int i;
  286.     int glp,grp,fsp;
  287.  
  288.     glp=gl*fsize/639;
  289.     grp=gr*fsize/639;
  290.     fsp=grp-glp;
  291.     if (fsp>0)
  292.     {
  293.         for (i=0;i<32;i++)                    /* header */
  294.             ss[i]=s[i];
  295.         for (i=0;i<(fsp+32);i++)            /* copy */
  296.             ss[i+32]=s[32+glp+i];
  297.         for (i=(fsp+32);i<(256*1024-32);i++)/* clear */
  298.             ss[i+32]=128;
  299.         ss[12]=fsp % 256;                    /* new size */
  300.         ss[13]=(fsp/256) % 256;
  301.         ss[14]=(fsp/256/256) % 256;
  302.         ss[15]=fsp/256/256/256;
  303.         ss[16]=ss[17]=ss[18]=ss[19]=0;        /* loop point */
  304.         ss[20]=ss[21]=ss[22]=ss[23]=0;        /* loop length */
  305.         ffs=fsp+32;                            /* new file size */
  306.         ssplay (fsp);
  307.     }
  308. }
  309.  
  310. filename_in ()                /* ファイルネーム入力 */
  311. {
  312.     char q=0;
  313.     int p;
  314.     char mes[80];
  315.  
  316.     for (p=0;p<12;p++)
  317.         fn[p]=0;
  318.     p=0;
  319.     KBD_click (0);
  320.     while (q!=(char)13)
  321.     {
  322.         EGC_linebf256 (0,380,1023,511,0);
  323.         EGB_gprint (32,380,"ファイルネームを入力してください。");
  324.         EGB_gprint (32,400,"無効なネームを入力するとキャンセルします。");
  325.         EGB_gprint (32,420,"「.snd」は省略できません。CRで決定。");
  326.         sprintf (&mes[0],"保存名称「%s」 : debug (%d) (%d)",&fn[0],p,(uint)q);
  327.         EGB_gprint (0,440,&mes[0]);
  328.         q=(char)KBD_inkey ();
  329.         if (q>(char)31)
  330.             fn[p++]=q;
  331.         if (p>=11) p=11;
  332.         if ((q==(char)8) && (p>0))
  333.         {
  334.             fn[--p]=0;
  335.             EGB_gprint (480,440,"DELETE(debug)");
  336.         }
  337.     }
  338.     fn[++p]=0;
  339.     KBD_click (1);
  340. }
  341.  
  342. byebee_menu ()                    /* プログラムの終了 メニューに帰る */
  343. {
  344.     uint i;
  345.  
  346.     EGB_palette (0,255,0,0,0);
  347.     EGB_backcolor (0xff);
  348.     EGB_writecolor (0);
  349.     EGB_cls ();
  350.     EGB_gprint (200,160,"TOWNS-MENUに戻ります。");
  351.     for (i=0;i<=255;i+=4)
  352.         EGB_palette (1,255,i,i,i);
  353.     exit (0);
  354. }
  355.